
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>学并思-留言板</title>

    <!-- Bootstrap core CSS -->
    <link href="./Public/css/bootstrap.min.css" rel="stylesheet">
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <form class="navbar-form navbar-right">
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">登录</button>
            <a href="./reg.php" class="btn btn-success">注册</a>
          </form>
        </div>
      </div>
    </nav>

    <!-- Main jumbotron for a primary marketing message or call to action -->


    <div class="container" style="padding-top:80px;">
      <!-- Example row of columns -->
      <div class="row">
		<!-- 循环数据库中的留言信息 -->
      	<?php foreach ($data as $k => $v) { ?>
          <div class="alert alert-success" role="alert">
          <strong><?php echo $v['username'] ?>:</strong><?php echo $v['content'] ?>（  <?php echo Ctime($v['create_time']) ?>  ）
          <btn msg-id="<?php echo $k ?>"  class="btn btn-danger btn-xs del-msg">删除</btn>
          <a href="./edit.php?id=<?php echo $k ?>"  class="btn btn-info btn-xs">修改</a>
          </div>
        <?php } ?>
        
      	<form action="./add.php" method="post" class="form-inline">
		  <div class="form-group">
		    <label class="sr-only" for="exampleInputAmount">大侠叫什么</label>
		    <div class="input-group">
		      <div class="input-group-addon">用户名</div>
		      <input type="text" class="form-control" name="username"  id="exampleInputAmount" placeholder="大侠叫什么">
		    </div>
		  </div>
		  <button type="submit" class="btn btn-primary">留言</button>
		  <br>
		  <textarea style="margin-top:20px;width:100%" class="form-control" rows="3" name="content"></textarea>
		</form>

      </div>

      <hr>

      <footer>
        <p>&copy; 2016 Company, Inc.</p>
      </footer>
    </div> 
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript">

        $(function  () {
            $('.del-msg').click(function(event) {
                dataid= $(this).attr('msg-id');

                obj = $(this);

                if(confirm("是否确定要删除")){
                  $.ajax({
                    url: './delAjax.php',
                    type: 'post',
                    dataType: 'json',
                    data: {id: dataid,name:"zhibinm"},
                  })
                  .done(function(res) {
                      if(res.error==0){
                        obj.parents('.alert').remove();
                      }
                  })
                  .fail(function() {
                      alert("删除失败，通讯不成功");
                  })
                }
            });

        })

    </script>
  </body>
</html>
